﻿using Microsoft.EntityFrameworkCore;
using AhCha.Fortunate.EntityFrameworkCore;

namespace AhCha.Fortunate.Repositories.EntityFrameworkCore
{
    public class EntityFrameworkCoreRepository<T> : IEntityFrameworkCoreRepository<T> where T : class
    {
        private readonly AhChaFortunateContext context;
        private readonly DbSet<T> dbSet;

        public EntityFrameworkCoreRepository(AhChaFortunateContext _context)
        {
            context = _context;
            dbSet = _context.Set<T>();
        }

        public async Task Insert(T entity)
        {
            await dbSet.AddAsync(entity);
            await context.SaveChangesAsync();
        }
    }
}
